//
//  CollectionCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/15.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class CollectionCell: MGSwipeTableCell {

    // MARK: - life cycle
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.contentView.addSubview(iconImageView)
        self.contentView.addSubview(productLabel)
        self.contentView.addSubview(netContentLabel)
        self.contentView.addSubview(colorNumLabel)
        self.contentView.addSubview(lowStockLabel)
        self.contentView.addSubview(priceLabel)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(contentLabel)
        self.contentView.addSubview(lineView)
    }
    
    func layoutPageSubviews() {
        iconImageView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(20)
            make.top.equalTo(self).offset(14)
            make.width.height.equalTo(100)
        }
        
        productLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(self).offset(28)
            make.width.equalTo(100)
            make.height.equalTo(14)
        }
        
        netContentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(productLabel.snp.bottom).offset(10)
            make.width.equalTo(83)
            make.height.equalTo(12)
        }
        
        colorNumLabel.snp.makeConstraints { (make) in
            make.left.equalTo(productLabel.snp.right).offset(5)
            make.top.equalTo(productLabel.snp.bottom).offset(10)
            make.width.equalTo(70)
            make.height.equalTo(12)
        }
        
        lowStockLabel.snp.makeConstraints { (make) in
            make.top.equalTo(netContentLabel.snp.bottom).offset(8)
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.width.equalTo(48)
            make.height.equalTo(12)
        }
        
        priceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.top.equalTo(netContentLabel.snp.bottom).offset(32)
            make.width.equalTo(64)
            make.height.equalTo(14)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(12)
            make.top.equalTo(self).offset(21)
            make.right.equalTo(self).offset(-14)
            make.height.equalTo(27)
        }
        
        contentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(12)
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
            make.right.equalTo(self).offset(-14)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(14)
            make.bottom.equalTo(self).offset(0)
            make.right.equalTo(self).offset(0)
            make.height.equalTo(1)
        }
    }
    
    func configUI() {
        iconImageView.sd_setImage(with: URL(string: "http://img15.3lian.com/2015/h1/57/d/61.jpg"), placeholderImage: UIImage(named: "def_162x162"))
        productLabel.text = "苦橙收敛调理液"
        netContentLabel.text = "净含量：200ml"
        colorNumLabel.text = "色号：#456"
        lowStockLabel.text = "库存紧张"
        priceLabel.text = "￥335.00"
        titleLabel.text = "Larme de Sirene/人鱼之水"
        contentLabel.text = "来自法国的Larme de Sirene设计灵感来源于希腊神话中的人鱼Sirene使它具有令人着迷的神秘感，采用进口水晶制作的瓶身，外观精美又大气"
    }
    
    // MARK: - setters and getters
    var _index: Int?
    var index: Int? {
        set {
            
            if newValue == 0 {
                productLabel.isHidden = false
                netContentLabel.isHidden = false
                colorNumLabel.isHidden = false
                lowStockLabel.isHidden = false
                priceLabel.isHidden = false
                titleLabel.isHidden = true
                contentLabel.isHidden = true
            } else if newValue == 1 {
                productLabel.isHidden = true
                netContentLabel.isHidden = true
                colorNumLabel.isHidden = true
                lowStockLabel.isHidden = true
                priceLabel.isHidden = true
                titleLabel.isHidden = false
                contentLabel.isHidden = false
            }
        } get {
            return _index
        }
    }
    
    var _isOrder: Bool?
    var isOrder: Bool? {
        set {
            if newValue! {
                colorNumLabel.isHidden = true
                lowStockLabel.isHidden = true
            }
        } get {
            return _isOrder
        }
    }
    
    var _iconImageView: UIImageView!
    var iconImageView: UIImageView {
        if _iconImageView == nil {
            _iconImageView = UIImageView()
        }
        return _iconImageView
    }
    
    var _productLabel: UILabel!
    var productLabel: UILabel {
        if _productLabel == nil {
            _productLabel = UILabel()
            _productLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _productLabel.textColor = UIColor(hexString: "#252525")
        }
        return _productLabel
    }
    
    var _netContentLabel: UILabel!
    var netContentLabel: UILabel {
        if _netContentLabel == nil {
            _netContentLabel = UILabel()
            _netContentLabel.font = UIFont(name: "PingFangSC-Light", size: 12)
            _netContentLabel.textColor = UIColor(hexString: "#999999")
        }
        return _netContentLabel
    }
    
    var _colorNumLabel: UILabel!
    var colorNumLabel: UILabel {
        if _colorNumLabel == nil {
            _colorNumLabel = UILabel()
            _colorNumLabel.font = UIFont(name: "PingFangSC-Light", size: 12)
            _colorNumLabel.textColor = UIColor(hexString: "#999999")
            //            _colorNumLabel.isHidden = true
        }
        return _colorNumLabel
    }
    
    var _lowStockLabel: UILabel!
    var lowStockLabel: UILabel {
        if _lowStockLabel == nil {
            _lowStockLabel = UILabel()
            _lowStockLabel.font = UIFont(name: "PingFangSC-Light", size: 12)
            _lowStockLabel.textColor = UIColor(hexString: "#B7A18A")
            _lowStockLabel.text = "库存紧张"
            //            _lowStockLabel.isHidden = true
        }
        return _lowStockLabel
    }
    
    var _priceLabel: UILabel!
    var priceLabel: UILabel {
        if _priceLabel == nil {
            _priceLabel = UILabel()
            _priceLabel.font = UIFont(name: "PingFang-SC-Regular", size: 14)
            _priceLabel.textColor = UIColor(hexString: "#B50834")
        }
        return _priceLabel
    }
    
    var _titleLabel: UILabel!
    var titleLabel: UILabel {
        if _titleLabel == nil {
            _titleLabel = UILabel()
            _titleLabel.font = UIFont(name: "PingFangSC-Regular", size: 16)
            _titleLabel.textColor = UIColor(hexString: "#131313")
        }
        return _titleLabel
    }
    
    var _contentLabel: UILabel!
    var contentLabel: UILabel {
        if _contentLabel == nil {
            _contentLabel = UILabel()
            _contentLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
            _contentLabel.textColor = UIColor(hexString: "#999999")
            _contentLabel.numberOfLines = 0
        }
        return _contentLabel
    }
    
    var _lineView: UIView!
    var lineView: UIView {
        if _lineView == nil {
            _lineView = UIView()
            _lineView.backgroundColor = UIColor(hexString: "#DDDDDD")
        }
        return _lineView
    }

}
